//
//  Hound.m
//  TowerDefence
//
//  Created by K3 on 5/31/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "Hound.h"
#import "PlayScreen.h"

@implementation Hound

-(id)initHoundWith:(PlayScreen*)_playScreen withRoad:(NSMutableArray*)_road{
    self=[super initEnemyWith:_playScreen];
    armor=2;
    HP=50;
    speed=1.0f;
    spriteBody=[[CCSprite alloc]initWithSpriteFrameName:@"Hound_Move_01.png"];
    road = _road;
    damage = 15;
    nextHeadingPoint=1;
    [self drawBloodMeterWithLength:spriteBody.contentSize.width/2 + 10 width:3 position:ccp(spriteBody.contentSize.width/2, spriteBody.contentSize.height)];
    return self;
}

-(void)animationMoveLeft{
    //NSLog(@"Running");
    [super animationMoveLeft];
    CCAnimation *animation = [self loadAnimationFromCacheByName:@"Hound_Move" withCount:8 delay:0.08f];
    [spriteBody runAction:[CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:animation]]];
}

-(void)animationMoveUp{
    [super animationMoveUp];
    CCAnimation *animation = [self loadAnimationFromCacheByName:@"Hound_Move_Up" withCount:5 delay:0.1];
    [spriteBody runAction:[CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:animation]]];
}

-(void)animationMoveDown{
    [super animationMoveDown];
    CCAnimation *animation = [self loadAnimationFromCacheByName:@"Hound_Move_Down" withCount:5 delay:0.1];
    [spriteBody runAction:[CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:animation]]];
}

-(void)animationBattle{
    [super animationBattle];
    CCAnimation *animation = [self loadAnimationFromCacheByName:@"Hound_Attack" withCount:10 delay:0.1];
    CCCallFunc *func=[CCCallFunc actionWithTarget:self selector:@selector(battle)];
    [spriteBody runAction:[CCRepeatForever actionWithAction:[CCSequence actions:[CCAnimate actionWithAnimation:animation],[CCDelayTime actionWithDuration:0.5],func, nil]]];
}

-(void)animationDie{
    [super animationDie];
    CCAnimation *animation = [self loadAnimationFromCacheByName:@"Hound_Die" withCount:8 delay:0.1f];
    CCCallFunc *dieCallBack = [CCCallFunc actionWithTarget:self selector:@selector(dieCallBack)];
    [spriteBody runAction:[CCSequence actions:[CCAnimate actionWithAnimation:animation restoreOriginalFrame:NO],[CCDelayTime actionWithDuration:0.75f], dieCallBack, nil]];
}

-(void)dealloc {
    NSLog(@"Goblin dealoc");
    [self removeAnimationInFrameCache:@"Hound_Move"];
    [self removeAnimationInFrameCache:@"Hound_Move_Up"];
    [self removeAnimationInFrameCache:@"Hound_Move_Down"];
    [self removeAnimationInFrameCache:@"Hound_Attack"];
    [self removeAnimationInFrameCache:@"Hound_Die"];
    [super dealloc];
}

@end
